###De manera general sin importar las versiones.
data <- read.csv("/Users/jorgevargasmutizabal/Desktop/Frog game statistics/R Analysis Frog/filtered_data.csv")
# Filter the data for Phrase_Condition == 1
filtered_data <- data %>%
filter(Phrase_Condition == 1)
# Hard-code Rounds based on version and level
filtered_data <- filtered_data %>%
mutate(Rounds = case_when(
Game_Version == 1 & Game_Level == 1 ~ 1,
Game_Version == 1 & Game_Level == 3 ~ 2,
Game_Version == 1 & Game_Level == 7 ~ 3,
Game_Version == 1 & Game_Level == 8 ~ 4,
Game_Version == 2 & Game_Level == 5 ~ 1,
Game_Version == 2 & Game_Level == 6 ~ 2,
Game_Version == 2 & Game_Level == 7 ~ 3,
Game_Version == 2 & Game_Level == 8 ~ 4,
Game_Version == 3 & Game_Level == 4 ~ 1,
Game_Version == 3 & Game_Level == 6 ~ 2,
Game_Version == 3 & Game_Level == 7 ~ 3,
Game_Version == 3 & Game_Level == 8 ~ 4,
Game_Version == 4 & Game_Level == 2 ~ 1,
Game_Version == 4 & Game_Level == 3 ~ 2,
Game_Version == 4 & Game_Level == 7 ~ 3,
Game_Version == 4 & Game_Level == 8 ~ 4,
TRUE ~ NA_integer_
))
# Assuming your data frame is named df
summary_table <- filtered_data %>%
group_by(Game_Version, Game_Level, Rounds) %>%
summarise(Count = n(), .groups = 'drop')
print(summary_table)
## # A tibble: 16 × 4
## Game_Version Game_Level Rounds Count
## <int> <int> <dbl> <int>
## 1 1 1 1 418
## 2 1 3 2 214
## 3 1 7 3 108
## 4 1 8 4 107
## 5 2 5 1 468
## 6 2 6 2 268
## 7 2 7 3 108
## 8 2 8 4 118
## 9 3 4 1 476
## 10 3 6 2 238
## 11 3 7 3 129
## 12 3 8 4 132
## 13 4 2 1 474
## 14 4 3 2 425
## 15 4 7 3 118
## 16 4 8 4 142
#total number of conditions instance by level
filtered_data %>%
group_by(Rounds) %>%
summarise(Count = n())
## # A tibble: 4 × 2
## Rounds Count
## <dbl> <int>
## 1 1 1836
## 2 2 1145
## 3 3 463
## 4 4 499
filtered_data <- filtered_data %>%
mutate(
Player_ID = as.factor(Player_ID), # Convert to factor
LexTale = as.numeric(LexTale), # Convert to numeric
Game_Version = as.factor(Game_Version), # Convert to factor
Game_Level = as.numeric(Game_Level), # Convert to factor
Phrase_Condition = as.factor(Phrase_Condition), # Convert to factor
Question_Num = as.numeric(Question_Num), # Convert to numeric
Answer = as.numeric(Answer), # Convert to factor
Reaction_Time = as.numeric(Reaction_Time), # Convert to numeric
Rounds = as.numeric(Rounds) # Convert to numeric
)
# Fit the model with Game_Level as a numeric predictor
model0 <- lmer(Reaction_Time ~ 1 + Rounds + (1 | Player_ID), data = filtered_data)
# Print a summary of the model to examine fixed and random effects
print(summary(model0))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Reaction_Time ~ 1 + Rounds + (1 | Player_ID)
## Data: filtered_data
##
## REML criterion at convergence: 2219.9
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.4683 -0.6913 -0.1233 0.5382 4.5937
##
## Random effects:
## Groups Name Variance Std.Dev.
## Player_ID (Intercept) 0.01174 0.1083
## Residual 0.09997 0.3162
## Number of obs: 3943, groups: Player_ID, 38
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 5.741e-01 2.050e-02 5.841e+01 28.006 < 2e-16 ***
## Rounds 2.673e-02 4.854e-03 3.906e+03 5.506 3.9e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## Rounds -0.451
# Diagnostic plots for residuals - Adjusted for typical visualization tools in R
plot(model0)
# Additional model diagnostics from the 'performance' package
check_model(model0) # This function will check various model assumptions and fit indices
# Estimate marginal means at specific points along the Rounds
# You would need to know the range or specific points of interest.
# For example, if Game_Level ranges from 1 to 10, you might choose points like 1, 5, and 10.
emm0 <- emmeans(model0, specs = ~ Rounds, at = list(Rounds = c(1, 2,3,4)))
## Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
## To enable adjustments, add the argument 'pbkrtest.limit = 3943' (or larger)
## [or, globally, 'set emm_options(pbkrtest.limit = 3943)' or larger];
## but be warned that this may result in large computation time and memory use.
## Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
## To enable adjustments, add the argument 'lmerTest.limit = 3943' (or larger)
## [or, globally, 'set emm_options(lmerTest.limit = 3943)' or larger];
## but be warned that this may result in large computation time and memory use.
# Convert the summary to a data frame
emm0_df <- as.data.frame(summary(emm0))
# Then, you can plot these points as before:
emm_plot <- ggplot(emm0_df, aes(x = Rounds, y = emmean)) +
geom_point() + # Add points for each estimated marginal mean
geom_line() + # Connect the points with a line to show trends
geom_errorbar(aes(ymin = asymp.LCL, ymax = asymp.UCL), width = 0.1) + # Add error bars for confidence intervals
labs(title = "Estimated Marginal Means of Reaction Time by Rounds",
x = "Rounds",
y = "Estimated Marginal Mean Reaction Time") +
theme_minimal() # Use a minimal theme for a clean look
# Print the plot
print(emm_plot)
# Trend analysis for numeric Game_Level
# Assuming trend_analysis is already obtained and contains the trend estimate
# Determine the range of Game_Level you want to visualize
rounds <- seq(min(filtered_data$Rounds), max(filtered_data$Rounds), by = 1)
# Retrieve the actual coefficient for Rounds from the model
coef_estimate_for_rounds <- coef(summary(model0))['Rounds', 'Estimate']
# Calculate predicted reaction times based on the actual model coefficient
predicted_reaction_times <- coef_estimate_for_rounds * rounds + coef(summary(model0))["(Intercept)", "Estimate"]
# Create a dataframe for plotting
trend_data <- data.frame(Rounds = rounds, Predicted_Reaction_Time = predicted_reaction_times)
# Plotting the trend
trend_plot <- ggplot(trend_data, aes(x = Rounds, y = Predicted_Reaction_Time)) +
geom_line(color = "blue") +
labs(title = "Trend of Reaction Time Across Rounds",
x = "Rounds",
y = "Predicted Reaction Time") +
theme_minimal()
# Print the plot
print(trend_plot)
### Cond 1. Accuracy ### Same thing but for Answer(accuracy) (binomial
variable but logistic regression)
# Fit the model using glmer for a binary response
model0 <- glmer(Answer ~ 1 + Rounds + (1 | Player_ID), data = filtered_data, family = binomial)
# Print a summary of the model to examine fixed and random effects
print(summary(model0))
## Generalized linear mixed model fit by maximum likelihood (Laplace
## Approximation) [glmerMod]
## Family: binomial ( logit )
## Formula: Answer ~ 1 + Rounds + (1 | Player_ID)
## Data: filtered_data
##
## AIC BIC logLik deviance df.resid
## 1192.0 1210.8 -593.0 1186.0 3940
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -8.0692 0.1288 0.1533 0.1940 0.4131
##
## Random effects:
## Groups Name Variance Std.Dev.
## Player_ID (Intercept) 0.6636 0.8146
## Number of obs: 3943, groups: Player_ID, 38
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.73674 0.23377 15.985 <2e-16 ***
## Rounds -0.05039 0.07939 -0.635 0.526
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## Rounds -0.664
# Simulate residuals using DHARMa
simulationOutput <- simulateResiduals(fittedModel = model0, n = 250)
# Create diagnostic plots
plot(simulationOutput)
plotResiduals(simulationOutput)
plot(simulationOutput, type = "uniform")
plot(simulationOutput, type = "acf")
# Estimate marginal means at specific points along the Rounds
emm1 <- emmeans(model0, specs = ~ Rounds, at = list(Rounds = c(1, 2, 3, 4)), type = "response")
emm1_df <- as.data.frame(summary(emm1))
# Plot these points
emm_plot1 <- ggplot(emm1_df, aes(x = Rounds, y = prob)) +
geom_point() +
geom_line() +
geom_errorbar(aes(ymin = asymp.LCL, ymax = asymp.UCL), width = 0.1) +
labs(title = "Estimated Marginal Probabilities of Answer = 1 by Rounds",
x = "Rounds",
y = "Probability of Answer = 1") +
theme_minimal()
print(emm_plot1)
# Trend analysis for Rounds
trend_analysis1 <- emtrends(model0, specs = ~ Rounds, var = "Rounds")
# Calculate and plot predicted probabilities across Rounds
rounds <- seq(min(filtered_data$Rounds), max(filtered_data$Rounds), by = 1)
predicted_probs <- predict(model0, newdata = data.frame(Rounds = rounds), type = "response", re.form = NA)
trend_data1 <- data.frame(Rounds = rounds, Predicted_Probability = predicted_probs)
trend_plot1 <- ggplot(trend_data1, aes(x = Rounds, y = Predicted_Probability)) +
geom_line(color = "blue") +
labs(title = "Trend of Probability of Answer = 1 Across Rounds",
x = "Rounds",
y = "Predicted Probability") +
theme_minimal()
print(trend_plot1)
###Cond 2. Reaction time
data <- read.csv("/Users/jorgevargasmutizabal/Desktop/Frog game statistics/R Analysis Frog/filtered_data.csv")
# Filter the data for Phrase_Condition == 2
filtered_data <- data %>%
filter(Phrase_Condition == 2)
# Hard-code Rounds based on version and level
filtered_data <- filtered_data %>%
mutate(Rounds = case_when(
Game_Version == 1 & Game_Level == 2 ~ 1,
Game_Version == 1 & Game_Level == 3 ~ 2,
Game_Version == 1 & Game_Level == 7 ~ 3,
Game_Version == 1 & Game_Level == 8 ~ 4,
Game_Version == 2 & Game_Level == 1 ~ 1,
Game_Version == 2 & Game_Level == 3 ~ 2,
Game_Version == 2 & Game_Level == 7 ~ 3,
Game_Version == 2 & Game_Level == 8 ~ 4,
Game_Version == 3 & Game_Level == 5 ~ 1,
Game_Version == 3 & Game_Level == 6 ~ 2,
Game_Version == 3 & Game_Level == 7 ~ 3,
Game_Version == 3 & Game_Level == 8 ~ 4,
Game_Version == 4 & Game_Level == 4 ~ 1,
Game_Version == 4 & Game_Level == 6 ~ 2,
Game_Version == 4 & Game_Level == 7 ~ 3,
Game_Version == 4 & Game_Level == 8 ~ 4,
TRUE ~ NA_integer_
))
# Assuming your data frame is named df
summary_table <- filtered_data %>%
group_by(Game_Version, Game_Level, Rounds) %>%
summarise(Count = n(), .groups = 'drop')
print(summary_table)
## # A tibble: 16 × 4
## Game_Version Game_Level Rounds Count
## <int> <int> <dbl> <int>
## 1 1 2 1 423
## 2 1 3 2 214
## 3 1 7 3 107
## 4 1 8 4 106
## 5 2 1 1 409
## 6 2 3 2 277
## 7 2 7 3 106
## 8 2 8 4 113
## 9 3 5 1 472
## 10 3 6 2 237
## 11 3 7 3 128
## 12 3 8 4 128
## 13 4 4 1 551
## 14 4 6 2 283
## 15 4 7 3 116
## 16 4 8 4 143
#total number of conditions instance by level
filtered_data %>%
group_by(Rounds) %>%
summarise(Count = n())
## # A tibble: 4 × 2
## Rounds Count
## <dbl> <int>
## 1 1 1855
## 2 2 1011
## 3 3 457
## 4 4 490
filtered_data <- filtered_data %>%
mutate(
Player_ID = as.factor(Player_ID), # Convert to factor
LexTale = as.numeric(LexTale), # Convert to numeric
Game_Version = as.factor(Game_Version), # Convert to factor
Game_Level = as.numeric(Game_Level), # Convert to factor
Phrase_Condition = as.factor(Phrase_Condition), # Convert to factor
Question_Num = as.numeric(Question_Num), # Convert to numeric
Answer = as.numeric(Answer), # Convert to factor
Reaction_Time = as.numeric(Reaction_Time), # Convert to numeric
Rounds = as.numeric(Rounds) # Convert to numeric
)
#Fitting cond. 2 R.T
# Fit the model with Game_Level as a numeric predictor
model1 <- lmer(Reaction_Time ~ 1 + Rounds + (1 | Player_ID), data = filtered_data)
# Print a summary of the model to examine fixed and random effects
print(summary(model1))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Reaction_Time ~ 1 + Rounds + (1 | Player_ID)
## Data: filtered_data
##
## REML criterion at convergence: 1754.6
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.9832 -0.6522 -0.1356 0.4777 4.6107
##
## Random effects:
## Groups Name Variance Std.Dev.
## Player_ID (Intercept) 0.02593 0.161
## Residual 0.08939 0.299
## Number of obs: 3813, groups: Player_ID, 38
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 8.076e-01 2.797e-02 4.553e+01 28.876 < 2e-16 ***
## Rounds 2.652e-02 4.613e-03 3.775e+03 5.749 9.66e-09 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## Rounds -0.312
# Diagnostic plots for residuals - Adjusted for typical visualization tools in R
plot(model1)
# Additional model diagnostics from the 'performance' package
check_model(model1) # This function will check various model assumptions and fit indices
# Estimate marginal means at specific points along the Rounds
# You would need to know the range or specific points of interest.
# For example, if Game_Level ranges from 1 to 10, you might choose points like 1, 5, and 10.
emm0 <- emmeans(model1, specs = ~ Rounds, at = list(Rounds = c(1,2,3,4)))
## Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
## To enable adjustments, add the argument 'pbkrtest.limit = 3813' (or larger)
## [or, globally, 'set emm_options(pbkrtest.limit = 3813)' or larger];
## but be warned that this may result in large computation time and memory use.
## Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
## To enable adjustments, add the argument 'lmerTest.limit = 3813' (or larger)
## [or, globally, 'set emm_options(lmerTest.limit = 3813)' or larger];
## but be warned that this may result in large computation time and memory use.
# Convert the summary to a data frame
emm0_df <- as.data.frame(summary(emm0))
# Then, you can plot these points as before:
emm_plot <- ggplot(emm0_df, aes(x = Rounds, y = emmean)) +
geom_point() + # Add points for each estimated marginal mean
geom_line() + # Connect the points with a line to show trends
geom_errorbar(aes(ymin = asymp.LCL, ymax = asymp.UCL), width = 0.1) + # Add error bars for confidence intervals
labs(title = "Estimated Marginal Means of Reaction Time by Rounds",
x = "Rounds",
y = "Estimated Marginal Mean Reaction Time") +
theme_minimal() # Use a minimal theme for a clean look
# Print the plot
print(emm_plot)
# Trend analysis for numeric Game_Level
# Assuming trend_analysis is already obtained and contains the trend estimate
# Determine the range of Game_Level you want to visualize
rounds <- seq(min(filtered_data$Rounds), max(filtered_data$Rounds), by = 1)
# Retrieve the actual coefficient for Rounds from the model
coef_estimate_for_rounds <- coef(summary(model0))['Rounds', 'Estimate']
# Calculate predicted reaction times based on the actual model coefficient
predicted_reaction_times <- coef_estimate_for_rounds * rounds + coef(summary(model1))["(Intercept)", "Estimate"]
# Create a dataframe for plotting
trend_data <- data.frame(Rounds = rounds, Predicted_Reaction_Time = predicted_reaction_times)
# Plotting the trend
trend_plot <- ggplot(trend_data, aes(x = Rounds, y = Predicted_Reaction_Time)) +
geom_line(color = "blue") +
labs(title = "Trend of Reaction Time Across Rounds",
x = "Rounds",
y = "Predicted Reaction Time") +
theme_minimal()
# Print the plot
print(trend_plot)
###Accuracy cond. 2
# Fit the model using glmer for a binary response
model1 <- glmer(Answer ~ 1 + Rounds + (1 | Player_ID), data = filtered_data, family = binomial)
# Print a summary of the model to examine fixed and random effects
print(summary(model1))
## Generalized linear mixed model fit by maximum likelihood (Laplace
## Approximation) [glmerMod]
## Family: binomial ( logit )
## Formula: Answer ~ 1 + Rounds + (1 | Player_ID)
## Data: filtered_data
##
## AIC BIC logLik deviance df.resid
## 2141.3 2160.1 -1067.7 2135.3 3810
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -5.5396 0.2203 0.2640 0.3265 0.6564
##
## Random effects:
## Groups Name Variance Std.Dev.
## Player_ID (Intercept) 0.3825 0.6184
## Number of obs: 3813, groups: Player_ID, 38
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 2.62148 0.16146 16.236 <2e-16 ***
## Rounds -0.02509 0.05540 -0.453 0.651
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## Rounds -0.658
# Simulate residuals using DHARMa
simulationOutput <- simulateResiduals(fittedModel = model1, n = 250)
# Create diagnostic plots
plot(simulationOutput)
plotResiduals(simulationOutput)
plot(simulationOutput, type = "uniform")
plot(simulationOutput, type = "acf")
# Estimate marginal means at specific points along the Rounds
emm1 <- emmeans(model1, specs = ~ Rounds, at = list(Rounds = c(1, 2, 3, 4)), type = "response")
emm1_df <- as.data.frame(summary(emm1))
# Plot these points
emm_plot1 <- ggplot(emm1_df, aes(x = Rounds, y = prob)) +
geom_point() +
geom_line() +
geom_errorbar(aes(ymin = asymp.LCL, ymax = asymp.UCL), width = 0.1) +
labs(title = "Estimated Marginal Probabilities of Answer = 1 by Rounds",
x = "Rounds",
y = "Probability of Answer = 1") +
theme_minimal()
print(emm_plot1)
# Trend analysis for Rounds
trend_analysis1 <- emtrends(model1, specs = ~ Rounds, var = "Rounds")
# Calculate and plot predicted probabilities across Rounds
rounds <- seq(min(filtered_data$Rounds), max(filtered_data$Rounds), by = 1)
predicted_probs <- predict(model1, newdata = data.frame(Rounds = rounds), type = "response", re.form = NA)
trend_data1 <- data.frame(Rounds = rounds, Predicted_Probability = predicted_probs)
trend_plot1 <- ggplot(trend_data1, aes(x = Rounds, y = Predicted_Probability)) +
geom_line(color = "blue") +
labs(title = "Trend of Probability of Answer = 1 Across Rounds",
x = "Rounds",
y = "Predicted Probability") +
theme_minimal()
print(trend_plot1)
data <- read.csv("/Users/jorgevargasmutizabal/Desktop/Frog game statistics/R Analysis Frog/filtered_data.csv")
# Filter the data for Phrase_Condition == 3
filtered_data <- data %>%
filter(Phrase_Condition == 3)
# Hard-code Rounds based on version and level
filtered_data <- filtered_data %>%
mutate(Rounds = case_when(
Game_Version == 1 & Game_Level == 4 ~ 1,
Game_Version == 1 & Game_Level == 6 ~ 2,
Game_Version == 1 & Game_Level == 7 ~ 3,
Game_Version == 1 & Game_Level == 8 ~ 4,
Game_Version == 2 & Game_Level == 2 ~ 1,
Game_Version == 2 & Game_Level == 3 ~ 2,
Game_Version == 2 & Game_Level == 7 ~ 3,
Game_Version == 2 & Game_Level == 8 ~ 4,
Game_Version == 3 & Game_Level == 1 ~ 1,
Game_Version == 3 & Game_Level == 3 ~ 2,
Game_Version == 3 & Game_Level == 7 ~ 3,
Game_Version == 3 & Game_Level == 8 ~ 4,
Game_Version == 4 & Game_Level == 5 ~ 1,
Game_Version == 4 & Game_Level == 6 ~ 2,
Game_Version == 4 & Game_Level == 7 ~ 3,
Game_Version == 4 & Game_Level == 8 ~ 4,
TRUE ~ NA_integer_
))
# Assuming your data frame is named df
summary_table <- filtered_data %>%
group_by(Game_Version, Game_Level, Rounds) %>%
summarise(Count = n(), .groups = 'drop')
print(summary_table)
## # A tibble: 16 × 4
## Game_Version Game_Level Rounds Count
## <int> <int> <dbl> <int>
## 1 1 4 1 473
## 2 1 6 2 237
## 3 1 7 3 108
## 4 1 8 4 108
## 5 2 2 1 479
## 6 2 3 2 280
## 7 2 7 3 105
## 8 2 8 4 119
## 9 3 1 1 554
## 10 3 3 2 347
## 11 3 7 3 129
## 12 3 8 4 131
## 13 4 5 1 677
## 14 4 6 2 284
## 15 4 7 3 120
## 16 4 8 4 143
#total number of conditions instance by level
filtered_data %>%
group_by(Rounds) %>%
summarise(Count = n())
## # A tibble: 4 × 2
## Rounds Count
## <dbl> <int>
## 1 1 2183
## 2 2 1148
## 3 3 462
## 4 4 501
filtered_data <- filtered_data %>%
mutate(
Player_ID = as.factor(Player_ID), # Convert to factor
LexTale = as.numeric(LexTale), # Convert to numeric
Game_Version = as.factor(Game_Version), # Convert to factor
Game_Level = as.numeric(Game_Level), # Convert to factor
Phrase_Condition = as.factor(Phrase_Condition), # Convert to factor
Question_Num = as.numeric(Question_Num), # Convert to numeric
Answer = as.numeric(Answer), # Convert to factor
Reaction_Time = as.numeric(Reaction_Time), # Convert to numeric
Rounds = as.numeric(Rounds) # Convert to numeric
)
##fitting cond. 3
# Fit the model with Game_Level as a numeric predictor
model2 <- lmer(Reaction_Time ~ 1 + Rounds + (1 | Player_ID), data = filtered_data)
# Print a summary of the model to examine fixed and random effects
print(summary(model2))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Reaction_Time ~ 1 + Rounds + (1 | Player_ID)
## Data: filtered_data
##
## REML criterion at convergence: 4014.3
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.3998 -0.7194 -0.1690 0.5611 3.6936
##
## Random effects:
## Groups Name Variance Std.Dev.
## Player_ID (Intercept) 0.01774 0.1332
## Residual 0.14523 0.3811
## Number of obs: 4294, groups: Player_ID, 38
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 5.988e-01 2.485e-02 5.593e+01 24.098 < 2e-16 ***
## Rounds 3.239e-02 5.751e-03 4.266e+03 5.633 1.88e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## Rounds -0.431
# Diagnostic plots for residuals - Adjusted for typical visualization tools in R
plot(model2)
# Additional model diagnostics from the 'performance' package
check_model(model2) # This function will check various model assumptions and fit indices
# Estimate marginal means at specific points along the Rounds
# You would need to know the range or specific points of interest.
# For example, if Game_Level ranges from 1 to 10, you might choose points like 1, 5, and 10.
emm0 <- emmeans(model0, specs = ~ Rounds, at = list(Rounds = c(1, 2,3,4)))
# Convert the summary to a data frame
emm0_df <- as.data.frame(summary(emm0))
# Then, you can plot these points as before:
emm_plot <- ggplot(emm0_df, aes(x = Rounds, y = emmean)) +
geom_point() + # Add points for each estimated marginal mean
geom_line() + # Connect the points with a line to show trends
geom_errorbar(aes(ymin = asymp.LCL, ymax = asymp.UCL), width = 0.1) + # Add error bars for confidence intervals
labs(title = "Estimated Marginal Means of Reaction Time by Rounds",
x = "Rounds",
y = "Estimated Marginal Mean Reaction Time") +
theme_minimal() # Use a minimal theme for a clean look
# Print the plot
print(emm_plot)
# Trend analysis for numeric Game_Level
# Assuming trend_analysis is already obtained and contains the trend estimate
# Determine the range of Game_Level you want to visualize
rounds <- seq(min(filtered_data$Rounds), max(filtered_data$Rounds), by = 1)
# Retrieve the actual coefficient for Rounds from the model
coef_estimate_for_rounds <- coef(summary(model0))['Rounds', 'Estimate']
# Calculate predicted reaction times based on the actual model coefficient
predicted_reaction_times <- coef_estimate_for_rounds * rounds + coef(summary(model0))["(Intercept)", "Estimate"]
# Create a dataframe for plotting
trend_data <- data.frame(Rounds = rounds, Predicted_Reaction_Time = predicted_reaction_times)
# Plotting the trend
trend_plot <- ggplot(trend_data, aes(x = Rounds, y = Predicted_Reaction_Time)) +
geom_line(color = "blue") +
labs(title = "Trend of Reaction Time Across Rounds",
x = "Rounds",
y = "Predicted Reaction Time") +
theme_minimal()
# Print the plot
print(trend_plot)
#Cond. 3 Accuracy
# Fit the model using glmer for a binary response
model2 <- glmer(Answer ~ 1 + Rounds + (1 | Player_ID), data = filtered_data, family = binomial)
# Print a summary of the model to examine fixed and random effects
print(summary(model1))
## Generalized linear mixed model fit by maximum likelihood (Laplace
## Approximation) [glmerMod]
## Family: binomial ( logit )
## Formula: Answer ~ 1 + Rounds + (1 | Player_ID)
## Data: filtered_data
##
## AIC BIC logLik deviance df.resid
## 2141.3 2160.1 -1067.7 2135.3 3810
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -5.5396 0.2203 0.2640 0.3265 0.6564
##
## Random effects:
## Groups Name Variance Std.Dev.
## Player_ID (Intercept) 0.3825 0.6184
## Number of obs: 3813, groups: Player_ID, 38
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 2.62148 0.16146 16.236 <2e-16 ***
## Rounds -0.02509 0.05540 -0.453 0.651
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## Rounds -0.658
# Simulate residuals using DHARMa
simulationOutput <- simulateResiduals(fittedModel = model2, n = 250)
# Create diagnostic plots
plot(simulationOutput)
plotResiduals(simulationOutput)
plot(simulationOutput, type = "uniform")
plot(simulationOutput, type = "acf")
# Estimate marginal means at specific points along the Rounds
emm1 <- emmeans(model2, specs = ~ Rounds, at = list(Rounds = c(1, 2, 3, 4)), type = "response")
emm1_df <- as.data.frame(summary(emm1))
# Plot these points
emm_plot1 <- ggplot(emm1_df, aes(x = Rounds, y = prob)) +
geom_point() +
geom_line() +
geom_errorbar(aes(ymin = asymp.LCL, ymax = asymp.UCL), width = 0.1) +
labs(title = "Estimated Marginal Probabilities of Answer = 1 by Rounds",
x = "Rounds",
y = "Probability of Answer = 1") +
theme_minimal()
print(emm_plot1)
# Trend analysis for Rounds
trend_analysis1 <- emtrends(model2, specs = ~ Rounds, var = "Rounds")
# Calculate and plot predicted probabilities across Rounds
rounds <- seq(min(filtered_data$Rounds), max(filtered_data$Rounds), by = 1)
predicted_probs <- predict(model1, newdata = data.frame(Rounds = rounds), type = "response", re.form = NA)
trend_data1 <- data.frame(Rounds = rounds, Predicted_Probability = predicted_probs)
trend_plot1 <- ggplot(trend_data1, aes(x = Rounds, y = Predicted_Probability)) +
geom_line(color = "blue") +
labs(title = "Trend of Probability of Answer = 1 Across Rounds",
x = "Rounds",
y = "Predicted Probability") +
theme_minimal()
print(trend_plot1)
data <- read.csv("/Users/jorgevargasmutizabal/Desktop/Frog game statistics/R Analysis Frog/filtered_data.csv")
# Filter the data for Phrase_Condition == 4
filtered_data <- data %>%
filter(Phrase_Condition == 4)
# Hard-code Rounds based on version and level
filtered_data <- filtered_data %>%
mutate(Rounds = case_when(
Game_Version == 1 & Game_Level == 5 ~ 1,
Game_Version == 1 & Game_Level == 6 ~ 2,
Game_Version == 1 & Game_Level == 7 ~ 3,
Game_Version == 1 & Game_Level == 8 ~ 4,
Game_Version == 2 & Game_Level == 4 ~ 1,
Game_Version == 2 & Game_Level == 6 ~ 2,
Game_Version == 2 & Game_Level == 7 ~ 3,
Game_Version == 2 & Game_Level == 8 ~ 4,
Game_Version == 3 & Game_Level == 2 ~ 1,
Game_Version == 3 & Game_Level == 3 ~ 2,
Game_Version == 3 & Game_Level == 7 ~ 3,
Game_Version == 3 & Game_Level == 8 ~ 4,
Game_Version == 4 & Game_Level == 1 ~ 1,
Game_Version == 4 & Game_Level == 3 ~ 2,
Game_Version == 4 & Game_Level == 7 ~ 3,
Game_Version == 4 & Game_Level == 8 ~ 4,
TRUE ~ NA_integer_
))
# Assuming your data frame is named df
summary_table <- filtered_data %>%
group_by(Game_Version, Game_Level, Rounds) %>%
summarise(Count = n(), .groups = 'drop')
print(summary_table)
## # A tibble: 16 × 4
## Game_Version Game_Level Rounds Count
## <int> <int> <dbl> <int>
## 1 1 5 1 1298
## 2 1 6 2 228
## 3 1 7 3 107
## 4 1 8 4 106
## 5 2 4 1 1262
## 6 2 6 2 249
## 7 2 7 3 99
## 8 2 8 4 114
## 9 3 2 1 2133
## 10 3 3 2 335
## 11 3 7 3 124
## 12 3 8 4 120
## 13 4 1 1 2589
## 14 4 3 2 410
## 15 4 7 3 117
## 16 4 8 4 147
#total number of conditions instance by level
filtered_data %>%
group_by(Rounds) %>%
summarise(Count = n())
## # A tibble: 4 × 2
## Rounds Count
## <dbl> <int>
## 1 1 7282
## 2 2 1222
## 3 3 447
## 4 4 487
filtered_data <- filtered_data %>%
mutate(
Player_ID = as.factor(Player_ID), # Convert to factor
LexTale = as.numeric(LexTale), # Convert to numeric
Game_Version = as.factor(Game_Version), # Convert to factor
Game_Level = as.numeric(Game_Level), # Convert to factor
Phrase_Condition = as.factor(Phrase_Condition), # Convert to factor
Question_Num = as.numeric(Question_Num), # Convert to numeric
Answer = as.numeric(Answer), # Convert to factor
Reaction_Time = as.numeric(Reaction_Time), # Convert to numeric
Rounds = as.numeric(Rounds) # Convert to numeric
)
# Fit the model with Game_Level as a numeric predictor
model3 <- lmer(Reaction_Time ~ 1 + Rounds + (1 | Player_ID), data = filtered_data)
# Print a summary of the model to examine fixed and random effects
print(summary(model3))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Reaction_Time ~ 1 + Rounds + (1 | Player_ID)
## Data: filtered_data
##
## REML criterion at convergence: 9050.5
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.9966 -0.7114 -0.0899 0.6491 3.3479
##
## Random effects:
## Groups Name Variance Std.Dev.
## Player_ID (Intercept) 0.03542 0.1882
## Residual 0.15013 0.3875
## Number of obs: 9438, groups: Player_ID, 38
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 1.016e+00 3.169e-02 4.136e+01 32.063 <2e-16 ***
## Rounds 4.273e-03 5.075e-03 9.409e+03 0.842 0.4
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## Rounds -0.230
# Diagnostic plots for residuals - Adjusted for typical visualization tools in R
plot(model3)
# Additional model diagnostics from the 'performance' package
check_model(model3) # This function will check various model assumptions and fit indices
# Estimate marginal means at specific points along the Rounds
# You would need to know the range or specific points of interest.
# For example, if Game_Level ranges from 1 to 10, you might choose points like 1, 5, and 10.
emm0 <- emmeans(model3, specs = ~ Rounds, at = list(Rounds = c(1, 2,3,4)))
## Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
## To enable adjustments, add the argument 'pbkrtest.limit = 9438' (or larger)
## [or, globally, 'set emm_options(pbkrtest.limit = 9438)' or larger];
## but be warned that this may result in large computation time and memory use.
## Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
## To enable adjustments, add the argument 'lmerTest.limit = 9438' (or larger)
## [or, globally, 'set emm_options(lmerTest.limit = 9438)' or larger];
## but be warned that this may result in large computation time and memory use.
# Convert the summary to a data frame
emm0_df <- as.data.frame(summary(emm0))
# Then, you can plot these points as before:
emm_plot <- ggplot(emm0_df, aes(x = Rounds, y = emmean)) +
geom_point() + # Add points for each estimated marginal mean
geom_line() + # Connect the points with a line to show trends
geom_errorbar(aes(ymin = asymp.LCL, ymax = asymp.UCL), width = 0.1) + # Add error bars for confidence intervals
labs(title = "Estimated Marginal Means of Reaction Time by Rounds",
x = "Rounds",
y = "Estimated Marginal Mean Reaction Time") +
theme_minimal() # Use a minimal theme for a clean look
# Print the plot
print(emm_plot)
# Trend analysis for numeric Game_Level
# Assuming trend_analysis is already obtained and contains the trend estimate
# Determine the range of Game_Level you want to visualize
rounds <- seq(min(filtered_data$Rounds), max(filtered_data$Rounds), by = 1)
# Retrieve the actual coefficient for Rounds from the model
coef_estimate_for_rounds <- coef(summary(model0))['Rounds', 'Estimate']
# Calculate predicted reaction times based on the actual model coefficient
predicted_reaction_times <- coef_estimate_for_rounds * rounds + coef(summary(model1))["(Intercept)", "Estimate"]
# Create a dataframe for plotting
trend_data <- data.frame(Rounds = rounds, Predicted_Reaction_Time = predicted_reaction_times)
# Plotting the trend
trend_plot <- ggplot(trend_data, aes(x = Rounds, y = Predicted_Reaction_Time)) +
geom_line(color = "blue") +
labs(title = "Trend of Reaction Time Across Rounds",
x = "Rounds",
y = "Predicted Reaction Time") +
theme_minimal()
# Print the plot
print(trend_plot)
##Cond.4 Accuracy
# Fit the model using glmer for a binary response
model3 <- glmer(Answer ~ 1 + Rounds + (1 | Player_ID), data = filtered_data, family = binomial)
# Print a summary of the model to examine fixed and random effects
print(summary(model3))
## Generalized linear mixed model fit by maximum likelihood (Laplace
## Approximation) [glmerMod]
## Family: binomial ( logit )
## Formula: Answer ~ 1 + Rounds + (1 | Player_ID)
## Data: filtered_data
##
## AIC BIC logLik deviance df.resid
## 11539.9 11561.4 -5767.0 11533.9 9435
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.9830 -1.3831 0.6185 0.6815 0.8532
##
## Random effects:
## Groups Name Variance Std.Dev.
## Player_ID (Intercept) 0.06728 0.2594
## Number of obs: 9438, groups: Player_ID, 38
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.84912 0.06435 13.196 <2e-16 ***
## Rounds 0.03019 0.02912 1.037 0.3
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## Rounds -0.646
# Simulate residuals using DHARMa
simulationOutput <- simulateResiduals(fittedModel = model1, n = 250)
# Create diagnostic plots
plot(simulationOutput)
plotResiduals(simulationOutput)
plot(simulationOutput, type = "uniform")
plot(simulationOutput, type = "acf")
# Estimate marginal means at specific points along the Rounds
emm1 <- emmeans(model3, specs = ~ Rounds, at = list(Rounds = c(1, 2, 3, 4)), type = "response")
emm1_df <- as.data.frame(summary(emm1))
# Plot these points
emm_plot1 <- ggplot(emm1_df, aes(x = Rounds, y = prob)) +
geom_point() +
geom_line() +
geom_errorbar(aes(ymin = asymp.LCL, ymax = asymp.UCL), width = 0.1) +
labs(title = "Estimated Marginal Probabilities of Answer = 1 by Rounds",
x = "Rounds",
y = "Probability of Answer = 1") +
theme_minimal()
print(emm_plot1)
# Trend analysis for Rounds
trend_analysis1 <- emtrends(model1, specs = ~ Rounds, var = "Rounds")
# Calculate and plot predicted probabilities across Rounds
rounds <- seq(min(filtered_data$Rounds), max(filtered_data$Rounds), by = 1)
predicted_probs <- predict(model1, newdata = data.frame(Rounds = rounds), type = "response", re.form = NA)
trend_data1 <- data.frame(Rounds = rounds, Predicted_Probability = predicted_probs)
trend_plot1 <- ggplot(trend_data1, aes(x = Rounds, y = Predicted_Probability)) +
geom_line(color = "blue") +
labs(title = "Trend of Probability of Answer = 1 Across Rounds",
x = "Rounds",
y = "Predicted Probability") +
theme_minimal()
print(trend_plot1)
# Fit the model using glmer for a binary response
model1 <- glmer(Answer ~ 1 + Rounds + (1 | Player_ID), data = filtered_data, family = binomial)
# Print a summary of the model to examine fixed and random effects
print(summary(model1))
## Generalized linear mixed model fit by maximum likelihood (Laplace
## Approximation) [glmerMod]
## Family: binomial ( logit )
## Formula: Answer ~ 1 + Rounds + (1 | Player_ID)
## Data: filtered_data
##
## AIC BIC logLik deviance df.resid
## 11539.9 11561.4 -5767.0 11533.9 9435
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.9830 -1.3831 0.6185 0.6815 0.8532
##
## Random effects:
## Groups Name Variance Std.Dev.
## Player_ID (Intercept) 0.06728 0.2594
## Number of obs: 9438, groups: Player_ID, 38
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.84912 0.06435 13.196 <2e-16 ***
## Rounds 0.03019 0.02912 1.037 0.3
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## Rounds -0.646
# Simulate residuals using DHARMa
simulationOutput <- simulateResiduals(fittedModel = model1, n = 250)
# Create diagnostic plots
plot(simulationOutput)
plotResiduals(simulationOutput)
plot(simulationOutput, type = "uniform")
plot(simulationOutput, type = "acf")
# Estimate marginal means at specific points along the Rounds
emm1 <- emmeans(model1, specs = ~ Rounds, at = list(Rounds = c(1, 2, 3, 4)), type = "response")
emm1_df <- as.data.frame(summary(emm1))
# Plot these points
emm_plot1 <- ggplot(emm1_df, aes(x = Rounds, y = prob)) +
geom_point() +
geom_line() +
geom_errorbar(aes(ymin = asymp.LCL, ymax = asymp.UCL), width = 0.1) +
labs(title = "Estimated Marginal Probabilities of Answer = 1 by Rounds",
x = "Rounds",
y = "Probability of Answer = 1") +
theme_minimal()
print(emm_plot1)
# Trend analysis for Rounds
trend_analysis1 <- emtrends(model1, specs = ~ Rounds, var = "Rounds")
# Calculate and plot predicted probabilities across Rounds
rounds <- seq(min(filtered_data$Rounds), max(filtered_data$Rounds), by = 1)
predicted_probs <- predict(model1, newdata = data.frame(Rounds = rounds), type = "response", re.form = NA)
trend_data1 <- data.frame(Rounds = rounds, Predicted_Probability = predicted_probs)
trend_plot1 <- ggplot(trend_data1, aes(x = Rounds, y = Predicted_Probability)) +
geom_line(color = "blue") +
labs(title = "Trend of Probability of Answer = 1 Across Rounds",
x = "Rounds",
y = "Predicted Probability") +
theme_minimal()
print(trend_plot1)
# Fit the model with Game_Level as a numeric predictor
model4 <- lmer(Reaction_Time ~ 1 + Game_Level + (1 | Player_ID), data = data)
# Print a summary of the model to examine fixed and random effects
print(summary(model4))
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Reaction_Time ~ 1 + Game_Level + (1 | Player_ID)
## Data: data
##
## REML criterion at convergence: 22205.6
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.4816 -0.7244 -0.1009 0.6079 3.6745
##
## Random effects:
## Groups Name Variance Std.Dev.
## Player_ID (Intercept) 0.01357 0.1165
## Residual 0.16333 0.4041
## Number of obs: 21488, groups: Player_ID, 38
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 8.831e-01 1.978e-02 4.255e+01 44.643 <2e-16 ***
## Game_Level -1.122e-02 1.255e-03 2.148e+04 -8.943 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## Game_Level -0.258
# Diagnostic plots for residuals - Adjusted for typical visualization tools in R
plot(model4)
# Additional model diagnostics from the 'performance' package
check_model(model4)
# Estimate marginal means at specific points along the Game_Level
emm0 <- emmeans(model4, specs = ~ Game_Level, at = list(Game_Level = c(1, 2, 3, 4, 5, 6, 7, 8))) #####
## Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
## To enable adjustments, add the argument 'pbkrtest.limit = 21488' (or larger)
## [or, globally, 'set emm_options(pbkrtest.limit = 21488)' or larger];
## but be warned that this may result in large computation time and memory use.
## Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
## To enable adjustments, add the argument 'lmerTest.limit = 21488' (or larger)
## [or, globally, 'set emm_options(lmerTest.limit = 21488)' or larger];
## but be warned that this may result in large computation time and memory use.
# Convert the summary to a data frame
emm0_df <- as.data.frame(summary(emm0))
# Then, you can plot these points
emm_plot <- ggplot(emm0_df, aes(x = Game_Level, y = emmean)) +
geom_point() +
geom_line() +
geom_errorbar(aes(ymin = asymp.LCL, ymax = asymp.UCL), width = 0.1) +
labs(title = "Estimated Marginal Means of Reaction Time by Game_Level",
x = "Game_Level",
y = "Estimated Marginal Mean Reaction Time") +
theme_minimal()
print(emm_plot)
# Trend analysis for numeric Game_Level
game_levels <- seq(min(data$Game_Level), max(data$Game_Level), by = 1)
# Retrieve the actual coefficient for Game_Level from the model
coef_estimate_for_gls <- coef(summary(model4))['Game_Level', 'Estimate']
# Calculate predicted reaction times based on the actual model coefficient
predicted_reaction_times <- coef_estimate_for_gls * game_levels + coef(summary(model0))["(Intercept)", "Estimate"]
# Create a dataframe for plotting
trend_data <- data.frame(Game_Level = game_levels, Predicted_Reaction_Time = predicted_reaction_times)
# Plotting the trend
trend_plot <- ggplot(trend_data, aes(x = Game_Level, y = Predicted_Reaction_Time)) +
geom_line(color = "blue") +
labs(title = "Trend of Reaction Time Across Game_Level",
x = "Game_Level",
y = "Predicted Reaction Time") +
theme_minimal()
print(trend_plot)
# Fit the model using glmer for a binary response
model5 <- glmer(Answer ~ 1 + Game_Level + (1 | Player_ID), data = data, family = binomial)
# Print a summary of the model to examine fixed and random effects
print(summary(model5))
## Generalized linear mixed model fit by maximum likelihood (Laplace
## Approximation) [glmerMod]
## Family: binomial ( logit )
## Formula: Answer ~ 1 + Game_Level + (1 | Player_ID)
## Data: data
##
## AIC BIC logLik deviance df.resid
## 19237.2 19261.2 -9615.6 19231.2 21485
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -4.2094 0.3169 0.4090 0.4922 0.6890
##
## Random effects:
## Groups Name Variance Std.Dev.
## Player_ID (Intercept) 0.1247 0.3531
## Number of obs: 21488, groups: Player_ID, 38
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 1.23856 0.06889 17.98 <2e-16 ***
## Game_Level 0.11857 0.00874 13.57 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## Game_Level -0.468
# Diagnostic plots for residuals - Adjusted for typical visualization tools in R
plot(model5)
# Additional model diagnostics from the 'performance' package
check_model(model5)
# Estimate marginal means at specific points along the Game_Level
emm0 <- emmeans(model5, specs = ~ Game_Level, at = list(Game_Level = c(1, 2, 3, 4, 5, 6, 7, 8))) #####
# Convert the summary to a data frame
emm0_df <- as.data.frame(summary(emm0))
# Convert the log odds (emmean) to probabilities
emm0_df$probability <- 1 / (1 + exp(-emm0_df$emmean))
# Then, you can plot these probabilities
emm_plot <- ggplot(emm0_df, aes(x = Game_Level, y = probability)) +
geom_point() +
geom_line() +
geom_errorbar(aes(ymin = 1 / (1 + exp(-asymp.LCL)), ymax = 1 / (1 + exp(-asymp.UCL))), width = 0.1) +
labs(title = "Predicted Probability of Correct Answer by Game_Level",
x = "Game_Level",
y = "Probability of Correct Answer") +
theme_minimal()
print(emm_plot)
# Trend analysis for numeric Game_Level
game_levels <- seq(min(data$Game_Level), max(data$Game_Level), by = 1)
# Retrieve the actual coefficient for Game_Level from the model
coef_estimate_for_gls <- coef(summary(model5))['Game_Level', 'Estimate']
# Calculate predicted log odds based on the actual model coefficient
predicted_log_odds <- coef_estimate_for_gls * game_levels + coef(summary(model5))["(Intercept)", "Estimate"]
# Convert predicted log odds to probabilities
predicted_probabilities <- 1 / (1 + exp(-predicted_log_odds))
# Create a dataframe for plotting
trend_data <- data.frame(Game_Level = game_levels, Predicted_Probability = predicted_probabilities)
# Plotting the trend of probabilities
trend_plot <- ggplot(trend_data, aes(x = Game_Level, y = Predicted_Probability)) +
geom_line(color = "blue") +
labs(title = "Trend of Predicted Probability Across Game_Level",
x = "Game_Level",
y = "Predicted Probability") +
theme_minimal()
print(trend_plot)